package com.example.lc.mydoubledisplay;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.Display;
import android.view.View;

/**
 * 双屏显示
 * 双屏显示Demo
 **/
public class MainActivity extends Activity implements PresentationHelper.Listener {
    // 双屏显示所用到的类
    PresentationHelper helper = null;
    PresentationFragment preso = null;
    Display display;
    private View inline;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        inline = findViewById(R.id.img_prose_view);
		helper=new PresentationHelper(this, this);
    }

    @Override
    public void showGuangGao(Display display) {
    // 这代码一定要加呀否则就不会分开来显示了
        this.display = display;
        if (inline.getVisibility() == View.VISIBLE) {
            inline.setVisibility(View.GONE);

            Fragment f = getFragmentManager().findFragmentById(
                    R.id.img_prose_view);

            getFragmentManager().beginTransaction().remove(f).commit();
        }
        preso = GuangGao.welcome(this, display);
        preso.show(getFragmentManager(), "showGuangGao");
    }

    @Override
    public void clearPreso(boolean switchToInline) {
        if (switchToInline) {
            inline.setVisibility(View.VISIBLE);
            // 48行
            getFragmentManager().beginTransaction()
                    .add(R.id.img_prose_view, buildPreso(null)).commit();
        }

        if (preso != null) {
            preso.dismiss();
            preso = null;
        }
    }

    private PresentationFragment buildPreso(Display display) {
        return (GuangGao.welcome(this, display));
    }

    /**
     * 重新获取
     */
    @Override
    public void onResume() {
        super.onResume();
        helper.onResume();
    }

    /**
     * 张婷
     */
    @Override
    public void onPause() {
        // onPause
        helper.onPause();
        super.onPause();
    }
}
